/*******************************************************************************
GSwicher.cpp

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-08-07

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/
#include "StdAfx.h"
#include "GSwicher.h"

#if (_OS_ == _OS_WINNT_)
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#endif//(_OS_ == _OS_WINNT_)

////////////////////////////////////////////////////////////////////////////////

GSwicher::GSwicher()
{
	m_pSrc = NULL;
	m_pTar = NULL;
}

GSwicher::~GSwicher()
{
	Free();
}

bool GSwicher::SceneSrc(GDC* pDC, GScene* pSrc)
{
	Free();
	m_nOffsetX = 0;
	m_nVel = 32;
	m_nWidth = pDC->gcWidth();
	m_pSrc = pDC->SceneShot(pSrc);
	return (m_pSrc != NULL ? true : false);
}

bool GSwicher::SceneTar(GDC* pDC, GScene* pTar)
{
	m_pTar = pDC->SceneShot(pTar);
	return (m_pTar != NULL ? true : false);
}


bool GSwicher::Swich(UINT nFlag, int nValue)
{
	if(m_pSrc && m_pTar)
	{
		m_nFlag = nFlag;
		m_nVel = nValue;
		return true;
	}
	return false;
}

void GSwicher::Free()
{
	delete m_pSrc;
	delete m_pTar;
	m_pSrc = NULL;
	m_pTar = NULL;
}

bool GSwicher::IsVisible()const
{
	if(m_nOffsetX >= 0 && m_nOffsetX < m_nWidth)
	{
		return true;
	}
	return false;
}

void GSwicher::OnDraw(GDC* pDC)
{
	if(m_pSrc && m_pTar)
	{
		int x = -m_nOffsetX;
		pDC->Draw(*m_pSrc, x, 0);

		x = m_nWidth - m_nOffsetX;
		pDC->Draw(*m_pTar, x, 0);
	}
}

LONG GSwicher::Update(UINT nMillisecond)
{
	switch(m_nFlag)
	{
	case SAF_DEFAULT:
	case SAF_RIGHT_TO_LEFT:
		m_nOffsetX += m_nVel;
		m_nVel += 24;
		break;
	case SAF_LEFT_TO_RIGHT:
	case SAF_TOP_TO_DOWN:
	case SAF_DOWN_TO_TOP:
	default:
		m_nOffsetX += m_nVel;
		m_nVel += 24;
		break;
	}
	return 0;
}

PMRV GSwicher::ProcMsg(GMsg& refMsg)
{
	return PM_PASS;
}
